/**
 * Created by asus on 2017/8/29.
 */
/**
 * 构建指定行数和列数的交叉点表格
 * @param rownum 行数
 * @param colnum 列数
 * @param tableId 生成表ID
 * @param xyInfo 指标和分组位置信息
 * @param optionInfo 指标和分组信息
 */
const dataTable = {
  //指标和分组都存在是调用
  createDataTable: function (rownum,colnum,tableId,xyInfo,optionInfo) {
    //取得指标和分组信息
    var idenGroupInfo = this.getIdenInfoGroupInfo(xyInfo,optionInfo);
    var idenInfo = idenGroupInfo.idenInfo;
    var groupInfo = idenGroupInfo.groupInfo;
    //根据指定的行数列数新建table
    var crossTable = $("#"+tableId);
    var iden = idenInfo[i];
    var group = groupInfo[j];
    for(var i = 0 ; i < rownum ; i ++){
      var trStr = "<tr >"
      var tdStr = "";
      for(var j = 0; j < colnum ; j ++){
        //取得cell对应的指标和分组信息
        if(xyInfo.rowType == "iden"){
          iden = idenInfo[i];
          group = groupInfo[j];
        }else {
          iden = idenInfo[j];
          group = groupInfo[i];
        }
        var period = (group.info.period != undefined && group.info.period != null && group.info.period != "") ? group.info.period :"";
        var idenPath = (iden.info.path != undefined && iden.info.path != null && iden.info.path != "") ? iden.info.path :"";
        var groupPath = (group.info.path != undefined && group.info.path != null && group.info.path != "") ? group.info.path :"";
        var idenPathName = (iden.info.pathName != undefined && iden.info.pathName != null && iden.info.pathName != "") ? iden.info.pathName :"";
        var groupPathName = (group.info.pathName != undefined && group.info.pathName != null && group.info.pathName != "") ? group.info.pathName :"";
        tdStr += "<td style='width: 100px;height: 35px;' rowidx='"+i+"' colidx='"+j+"' idenCode='"+iden.info.idenCode+"' idenPath='"+ idenPath +"' idenPathName='" + idenPathName +"' period='" + period 
          + "' groupCode='"+group.info.groupCode+"' groupPath='"+groupPath + "' groupPathName='" + groupPathName+"' isRegionCode='" + group.info.isRegionCode 
          + "'><input type='text' value='' placeholder='-'/><span style='display: none;'></span></td>";
      }
      trStr += tdStr;
      trStr += "</tr>";
      $(trStr).appendTo(crossTable);
    }
  },
  //分组不存在时候调用
  createDataTableNoGroups: function (tableId,cloumn,idneInfo) {
    //根据指定的行数列数新建table
    var crossTable = $("#"+tableId);
    var trStr = "<tr >"
    var tdStr = "";
    var iden;
    for(var j = 0; j < cloumn ; j ++){
      //取得cell对应的指标和分组信息
      iden = idneInfo[j];
      tdStr += "<td width='100' rindex='0' cindex='"+j+"' idenCode='"+iden.info.idenCode+"' groupCode='' isRegionCode=''><input type='text' placeholder='-' v-model='filter.region'/><span style='display: none;'></span></td>";
    }
    trStr += tdStr;
    trStr += "</tr>";
    $(trStr).appendTo(crossTable);
  },
  //根据位置关系获取指标数据和分组数据
  getIdenInfoGroupInfo: function (xyInfo,optionInfo) {
    var idenGroupInfo = {
      idenInfo:null,
      groupInfo:null
    };
    if(xyInfo.rowType == "iden"){
      idenGroupInfo.idenInfo = optionInfo.rowInfo;
      idenGroupInfo.groupInfo = optionInfo.colInfo;
    }else {
      idenGroupInfo.idenInfo = optionInfo.colInfo;
      idenGroupInfo.groupInfo = optionInfo.rowInfo;
    }
    return idenGroupInfo;
  }
}
export default dataTable

